<?php

/**
 * XHTML_Object, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Object class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_Common_Element.php";
include_once "XHTML__Special.php";
include_once "XHTML__Object_Content.php";


/**
 * The XHTML_Object class is a handler for the object xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_Object extends XHTML_Common_Element implements XHTML__Special {
    
    // xhtml attributes
    
    /**
     * Defines that the object should only be declared, not created or 
     * instantiated until needed.
     * 
     * @var boolean
     */
    protected $declare;
    
    /**
     * Class ID value as set in the Windows Registry or a URI.
     *
     * @var string
     */
    protected $classId;
    
    /**
     * URI where to find the code for the object.
     *
     * @var string
     */
    protected $codeBase;
    
    /**
     * URI that refers to the object's data.
     *
     * @var string
     */
    protected $data;
    
    /**
     * MIME type of data specified in the data attribute.
     *
     * @var string
     */
    protected $type;
    
    /**
     * Internet media type of the code referred to by the classid attribute.
     * 
     * @var string
     */
    protected $codeType;
    
    /**
     * A space separated list of URI's to archives. The archives contains 
     * resources relevant to the object.
     *
     * @var string
     */
    protected $archive;
    
    /**
     * Text to display while the object is loading.
     *
     * @var string
     */
    protected $standBy;
    
    /**
     * Height of the object. (nn for pixels or nn% for percentage)
     *
     * @var mixed
     */
    protected $height;
    
    /**
     * Width of the object. (nn for pixels or nn% for percentage)
     *
     * @var mixed
     */
    protected $width;
    
    /**
     * URI of a client-side image map to be used with the object.
     *
     * @var string
     */
    protected $useMap;
    
    /**
     * Unique name for the object (to use in scripts).
     *
     * @var string
     */
    protected $name;
    
    /**
     * Tab order number.
     *
     * @var string
     */
    protected $tabIndex;
    
    // inner elements
    
    /**
     * XHTML__Object_Content elements the object element has in its content.
     *
     * @var array
     */
    protected $elements;
    
    
    // Methods
    
    /**
     * Constructs a XHTML_Object object.
     */
    function __construct()
    {
        settype($this->elements, "array");
    }
    
    /**
     * Defines if the object should only be declared, not created or 
     * instantiated until needed.
     * 
     * @param boolean $declare
     */
    function setDeclare($declare) {
        $this->declare = $declare;
    }
    
    /**
     * Query if the object should only be declared, not created or 
     * instantiated until needed.
     * 
     * @return boolean
     */
    function isDeclare() {
        return $this->declare;
    }
    
    /**
     * Sets the class ID value as set in the Windows Registry or a URI.
     * 
     * @param string $classId
     */
    function setClassId($classId) {
        $this->classId = $classId;
    }
    
    /**
     * Gets the class ID value as set in the Windows Registry or a URI.
     * 
     * @return string
     */
    function getClassId() {
        return $this->classId;
    }
    
    /**
     * Sets the URI where to find the code for the object.
     *
     * @param string $codeBase
     */
    function setCodeBase($codeBase) {
        $this->codeBase = $codeBase;
    }
    
    /**
     * Gets the URI where to find the code for the object.
     * 
     * @return  string
     */
    function getCodeBase() {
        return $this->codeBase;
    }
    
    /**
     * Sets the URI that refers to the object's data.
     * 
     * @param string $data
     */
    function setData($data) {
        $this->data = $data;
    }
    
    /**
     * Gets the URI that refers to the object's data.
     * 
     * @return string
     */
    function getData() {
        return $this->data;
    }
    
    /**
     * Sets the MIME type of data specified in the data attribute.
     * 
     * @param string $type
     */
    function setType($type) {
        $this->type = $type;
    }
    
    /**
     * Gets the MIME type of data specified in the data attribute.
     *
     * @return string
     */
    function getType() {
        return $this->type;
    }
    
    /**
     * Sets the Internet media type of the code referred to by the classid 
     * attribute.
     * 
     * @param string $codeType
     */
    function setCodeType($codeType) {
        $this->codeType = $codeType;
    }
    
    /**
     * Gets the Internet media type of the code referred to by the classid 
     * attribute.
     *
     * @return string
     */
    function getCodeType() {
        return $this->codeType;
    }
    
    /**
     * Sets the space separated list of URI's to archives. The archives 
     * contains resources relevant to the object.
     * 
     * @param string $archive
     */
    function setArchive($archive) {
        $this->archive = $archive;
    }
    
    /**
     * Gets the space separated list of URI's to archives. The archives 
     * contains resources relevant to the object.
     * 
     * @return string
     */
    function getArchive() {
        return $this->archive;
    }
    
    /**
     * Sets the text to display while the object is loading.
     * 
     * @param string $standBy
     */
    function setStanBy($standBy) {
        $this->standBy = $standBy;
    }
    
    /**
     * Gets the text to display while the object is loading.
     * 
     * @return string
     */
    function getStandBy() {
        return $this->standBy;
    }
    
    /**
     * Sets the height of the object. (nn for pixels or nn% for percentage).
     * 
     * @param string $height
     */
    function setHeight($height) {
        $this->height = $height;
    }
    
    /**
     * Gets height of the object. (nn for pixels or nn% for percentage).
     * 
     * @return string
     */
    function getHeight() {
        return $this->height;
    }
    
    /**
     * Sets the width of the object. (nn for pixels or nn% for percentage).
     * 
     * @param string $width
     */
    function setWidth($width) {
        $this->width = $width;
    }
    
    /**
     * Gets width of the object. (nn for pixels or nn% for percentage).
     * 
     * @return string
     */
    function getWidth() {
        return $this->width;
    }
    
    /**
     * Sets the URI of a client-side image map to be used with the object.
     *
     * @param string $useMap
     */
    function setUseMap($useMap) {
        $this->useMap = $useMap;
    }
    
    /**
     * Gets the URI of a client-side image map to be used with the object.
     *
     * @return string
     */
    function getUseMap() {
        return $this->useMap;
    }
    
    /**
     * Sets the unique name for the object (to use in scripts).
     *
     * @param string $name
     */
    function setName($name) {
        $this->name = $name;
    }
    
    /**
     * Gets the unique name for the object (to use in scripts).
     * 
     * @return string
     */
    function getName() {
        return $this->name;
    }
    
    /**
     * Sets the tab order number.
     * 
     * @param integer $tabIndex
     */
    function setTabIndex($tabIndex) {
        $this->tabIndex = $tabIndex;
    }
    
    /**
     * Gets the tab order number.
     * 
     * @return integer
     */
    function getTabIndex() {
        return $this->tabIndex;
    }
 
    /**
     * Sets the XHTML_Inline elements array.
     *
     * @param array
     */
    function setElements($elements) {
        $this->elements = $elements;
    }
    
    /**
     * Gets the XHTML__Object_Content elements array.
     *
     * @return array
     */
    function getElements()
    {
        return $this->elements;
    }
    
    /**
     * Adds a XHTML__Object_Content element to the inner array of this object.
     * 
     * @param XHTML__Object_Content
     */
    function addElement(XHTML__Object_Content $element)
    {
        array_push($this->elements, $element);
    }
    
    /**
     * Removes a XHTML__Object_Content element from the inner array of this object.
     * 
     * @param XHTML__Object_Content
     */
    function removeElement(XHTML__Object_Content $element)
    {
        if (($res = array_search($element, $this->elements)) !== false) {
            unset($this->element[$res]);
        }
    }

    // Overriding the toString method for a proper implementation.
    
    /**
    * Returns the string representation for echoing the class atributes.
    *
    * @return string
    */
    function toString()
    {
        $auxString = "<object".parent::toString();
        
        /*
         * Additions of the object own attributes to the return string.
         */
        
        if ($this->declare) {
            $auxString = $auxString."declare=\"declare\" ";
        }
        
        if (isset($this->classId)) {
            $auxString = $auxString."classid=\"".$this->classId."\" ";
        }
        
        if (isset($this->codeBase)) {
            $auxString = $auxString."codebase=\"".$this->codebase."\" ";
        }
        
        if (isset($this->data)) {
            $auxString = $auxString."data=\"".$this->data."\" ";
        }
        
        if (isset($this->type)) {
            $auxString = $auxString."type=\"".$this->type."\" ";
        }
        
        if (isset($this->codeType)) {
            $auxString = $auxString."codetype=\"".$this->codetype."\" ";
        }
        
        if (isset($this->archive)) {
            $auxString = $auxString."archive=\"".$this->archive."\" ";
        }
        
        if (isset($this->standBy)) {
            $auxString = $auxString."standby=\"".$this->standBy."\" ";
        }
        
        if (isset($this->height)) {
            $auxString = $auxString."height=\"".$this->height."\" ";
        }
        
        if (isset($this->width)) {
            $auxString = $auxString."width=\"".$this->width."\" ";
        }
        
        if (isset($this->useMap)) {
            $auxString = $auxString."usemap=\"".$this->useMap."\" ";
        }
        
        if (isset($this->name)) {
            $auxString = $auxString."name=\"".$this->name."\" ";
        }
        
        if (isset($this->tabIndex)) {
            $auxString = $auxString."tabindex=\"".$this->tabIndex."\" ";
        }
        
        $auxString = $auxString.">\n";
        
        /*
         * Additions of the inner elements of the object element to the return 
         * string.
         */
        if (count($this->elements) > 0) {
            foreach ($this->elements as $element) {
                $auxString = $auxString.$element->toString();
            }
        }
        
        $auxString = $auxString."</object>\n";
        
        return $auxString;
    }
    
}

?>